package com.rocching.easychat.ui;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.rocching.easychat.R;
import com.rocching.easychat.core.ViewClickListener;
import com.rocching.easychat.db.LocalUserService;

import io.rong.imkit.RongIM;
import io.rong.imkit.userinfo.RongUserInfoManager;

public class FragmentMeConfigActivity extends AppCompatActivity {
    private final String TAG = FragmentMeConfigActivity.class.getName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fragment_me_config);

        init();
    }

    private void init() {
        ImageView back = findViewById(R.id.iv_back);
        TextView exit = findViewById(R.id.tv_exit);
        TextView clearCache = findViewById(R.id.tv_clear_cache);

        back.setOnClickListener(new ViewClickListener() {
            @Override
            public void onDClick(View v) {
                finish();
            }
        });
        exit.setOnClickListener(new ViewClickListener() {
            @Override
            public void onDClick(View v) {
                LocalUserService.getInstance().exit();

                RongIM.getInstance().logout();

                Intent intent = new Intent(getApplicationContext(), WelcomeActivity.class);
                startActivity(intent);
                finish();
            }
        });

        clearCache.setOnClickListener(new ViewClickListener() {
            @Override
            public void onDClick(View v) {
                RongUserInfoManager infoManager = RongUserInfoManager.getInstance();
                infoManager.clear();
            }
        });
    }
}